#! /usr/bin/python
# coding: utf-8

'''
+count chars: 前移count字符
-count chars: 后移count字符
+count lines: 前移count行
-count lines: 后移count行
linestart: 移动到行的开始
linesed: 移动到行的结束
wordstart: 移动到字的开始
wordend: 移动到字的结束
'''

# 演示修饰符表达式的使用方法， 如何与当前可用的indexes一起使用

from Tkinter import *

root = Tk()

t = Text()

for i in range(1, 10):
    t.insert(1.0, '0123456789\n')

a = 'test_mark'

def forwardChars():
    t.mark_set(a, INSERT + '+5c')
    # t.mark_set(a, INSERT + ' + 5 chars')

def backwardChars():
    t.mark_set(a, INSERT + '-5c')

def forwardLines():
    t.mark_set(a, INSERT + '+5l')

def backwardLines():
    t.mark_set(a, INSERT + '-5l')

def lineStart():
    t.mark_set(a, INSERT + ' linestart')

def lineEnd():
    t.mark_set(a, INSERT + ' lineend')

def wordStart():
    t.mark_set(a, INSERT + ' wordstart')

def wordEnd():
    t.mark_set(a, INSERT + ' wordend')

t.mark_set(a, INSERT)

Button(root, text='forward 5 chars', command=forwardChars).pack(fill=X)
Button(root, text='backward 5 chars', command=backwardChars).pack(fill=X)
Button(root, text='forward 5 lines', command=forwardLines).pack(fill=X)
Button(root, text='backward 5 lines', command=backwardLines).pack(fill=X)
Button(root, text='line start', command=lineStart).pack(fill=X)
Button(root, text='line end', command=lineEnd).pack(fill=X)
Button(root, text='word start', command=wordStart).pack(fill=X)
Button(root, text='word end', command=wordEnd).pack(fill=X)


def insertText():
    t.insert(INSERT, 'insert')

def currentText():
    t.insert(CURRENT, 'current')

def markText():
    t.insert(a, 'mark')

Button(root, text='insert jcodeer.cublog.cn', command=insertText).pack(fill=X)
Button(root, text='current jcodeer.cublog.cn', command=currentText).pack(fill=X)
Button(root, text='mark jcodeer.cublog.cn', command=markText).pack(fill=X)

t.pack()

root.mainloop()
